﻿Date.prototype.strftime = (function(){

	function strftime(format){
		var date = this;
		return (format + "").replace(
			//参数A
			/%([a-zA-Z])/g,
			//参数B
			function (m,f){
				var formatter = Date.formats && Date.formats[f];
				
				if(typeof formatter == "function"){
					return formatter.call(Date.formats,date)
				}else if(typeof formatter == "string"){
					return date.strftime(formatter);
				}
				
				return f;
			}
		);
	}
	
	function zeroPad(num){
		return (+num < 10 ? "0" : "") + num;
	}
	
	Date.formats = {
		d:function(date){
			return zeroPad(date.getDate());
		},
		m:function(date){
			return zeroPad(date.getMonth()+1);
		},
		y:function(date){
			return zeroPad(date.getYear()%100);
		},
		Y:function(date){
			return date.getFullYear();
		},
		F:"%Y-%m-%d",
		D:"%m/%d/%y"
	};
	return strftime;
	//自执行一次
}());

function assert(message,expr){
	if(!expr)
		throw new Error(message);
	assert.count++;
	return true;
}
assert.count = 0;

function testCase(name,test){
	assert.count = 0;
	var successful = 0;
	var testCount = 0;
	
	for(var test in tests){
		if(!/^test/.test(test)){
			continue;
		}
		
		testCount++;
		try{
			tests[test ]();
			output(test,"#0c0");
			successful++;
		}catch(e){
			output(test + "failed:" + e.message,"#c00");
		}
	}
	
	var color = successful == testCount ? "#0c0" : "#c00";
	output("<strong>" + testCount + "tests," + (testCount-successful)+"failures</strong>",color);
}